package com.huawei.appgallery.downloadengine.impl.smartmerge.jni;

import java.io.File;
import java.io.IOException;
import o.bnc;

public class AppPatch {
    private static int ʽ = 1;
    private static int ˊ = 0;
    private static final byte[] ˋ = new byte[]{(byte) 83, (byte) 121, (byte) -3, (byte) -47, (byte) -9, (byte) -30, (byte) -6, (byte) -19, (byte) -22, (byte) 25, (byte) -54, (byte) -14, (byte) -17, (byte) 5, (byte) -34, (byte) -36, (byte) 0, (byte) -22, (byte) 55};
    private static int ˎ = 45;
    private static AppPatch ˏ;
    private static final Object ॱ = new Object();

    private native int patch(String str, String str2, String str3);

    private java.lang.String ˋ() {
        /* JADX: method processing error */
/*
Error: jadx.core.utils.exceptions.DecodeException: Load method exception in method: com.huawei.appgallery.downloadengine.impl.smartmerge.jni.AppPatch.ˋ():java.lang.String
	at jadx.core.dex.nodes.MethodNode.load(MethodNode.java:116)
	at jadx.core.dex.nodes.ClassNode.load(ClassNode.java:249)
	at jadx.core.ProcessClass.process(ProcessClass.java:34)
	at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:306)
	at jadx.api.JavaClass.decompile(JavaClass.java:62)
Caused by: java.lang.NullPointerException
*/
        /*
        r0 = this;
        r0 = 1;
        r1 = 0;
        r3 = 0;
        r5 = "libapppatch.so";
        r2 = o.bnl.ˏ();
        r6 = r2.ॱ();
        r2 = new java.lang.StringBuilder;
        r2.<init>();
        r4 = r6.getFilesDir();
        r2 = r2.append(r4);
        r4 = "/";
        r2 = r2.append(r4);
        r2 = r2.append(r5);
        r2 = r2.toString();
        r4 = new java.io.File;
        r4.<init>(r2);
        r4 = r4.exists();
        if (r4 != 0) goto L_0x00f6;
    L_0x0033:
        r4 = ʽ;	 Catch:{ Exception -> 0x0148 }
        r4 = r4 + 57;
        r7 = r4 % 128;
        ˊ = r7;	 Catch:{ Exception -> 0x0148 }
        r4 = r4 % 2;	 Catch:{ Exception -> 0x0148 }
        if (r4 == 0) goto L_0x0145;
        switch(r0) {
            case 0: goto L_0x0102;
            default: goto L_0x0042;
        };
        r0 = r6.getAssets();	 Catch:{ IOException -> 0x009a, all -> 0x00cb }
        r3 = 2;
        r3 = new java.lang.Object[r3];	 Catch:{ all -> 0x00c3 }
        r4 = 1;	 Catch:{ all -> 0x00c3 }
        r3[r4] = r5;	 Catch:{ all -> 0x00c3 }
        r4 = 0;	 Catch:{ all -> 0x00c3 }
        r3[r4] = r0;	 Catch:{ all -> 0x00c3 }
        r0 = 5;	 Catch:{ all -> 0x00c3 }
        r4 = 0;	 Catch:{ all -> 0x00c3 }
        r7 = 15235; // 0x3b83 float:2.1349E-41 double:7.527E-320;	 Catch:{ all -> 0x00c3 }
        r0 = o.avb.ˏ(r0, r4, r7);	 Catch:{ all -> 0x00c3 }
        r0 = (java.lang.Class) r0;	 Catch:{ all -> 0x00c3 }
        r4 = "ˏ";	 Catch:{ all -> 0x00c3 }
        r7 = 2;	 Catch:{ all -> 0x00c3 }
        r7 = new java.lang.Class[r7];	 Catch:{ all -> 0x00c3 }
        r8 = 0;	 Catch:{ all -> 0x00c3 }
        r9 = android.content.res.AssetManager.class;	 Catch:{ all -> 0x00c3 }
        r7[r8] = r9;	 Catch:{ all -> 0x00c3 }
        r8 = 1;	 Catch:{ all -> 0x00c3 }
        r9 = java.lang.String.class;	 Catch:{ all -> 0x00c3 }
        r7[r8] = r9;	 Catch:{ all -> 0x00c3 }
        r0 = r0.getMethod(r4, r7);	 Catch:{ all -> 0x00c3 }
        r4 = 0;	 Catch:{ all -> 0x00c3 }
        r0 = r0.invoke(r4, r3);	 Catch:{ all -> 0x00c3 }
        r0 = (java.io.InputStream) r0;	 Catch:{ all -> 0x00c3 }
        r4 = r0.available();	 Catch:{ IOException -> 0x016b, all -> 0x0159 }
        r3 = new byte[r4];	 Catch:{ IOException -> 0x016b, all -> 0x0159 }
        r7 = r0.read(r3);	 Catch:{ IOException -> 0x016b, all -> 0x0159 }
        r8 = 0;	 Catch:{ IOException -> 0x016b, all -> 0x0159 }
        r8 = r8.length;	 Catch:{ IOException -> 0x016b, all -> 0x0159 }
        if (r7 == r4) goto L_0x00d5;
        o.dnw.ˎ(r1);
        o.dnw.ˎ(r0);
        r0 = ˊ;
        r0 = r0 + 77;
        r2 = r0 % 128;
        ʽ = r2;
        r0 = r0 % 2;
        if (r0 != 0) goto L_0x0155;
        r0 = 0;
        super.hashCode();	 Catch:{ all -> 0x0153 }
        r0 = r1;
        return r0;
    L_0x009a:
        r0 = move-exception;
        r2 = r1;
        r3 = r1;
        r4 = o.bnc.ˎ;	 Catch:{ all -> 0x0167 }
        r5 = "AppPatch";	 Catch:{ all -> 0x0167 }
        r6 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0167 }
        r6.<init>();	 Catch:{ all -> 0x0167 }
        r7 = "exception:copySoFile failed: ";	 Catch:{ all -> 0x0167 }
        r6 = r6.append(r7);	 Catch:{ all -> 0x0167 }
        r0 = r0.toString();	 Catch:{ all -> 0x0167 }
        r0 = r6.append(r0);	 Catch:{ all -> 0x0167 }
        r0 = r0.toString();	 Catch:{ all -> 0x0167 }
        r4.ˏ(r5, r0);	 Catch:{ all -> 0x0167 }
        o.dnw.ˎ(r2);
        o.dnw.ˎ(r3);
        r0 = r1;
        goto L_0x0099;
    L_0x00c3:
        r0 = move-exception;
        r2 = r0.getCause();	 Catch:{ IOException -> 0x009a, all -> 0x00cb }
        if (r2 == 0) goto L_0x00d4;	 Catch:{ IOException -> 0x009a, all -> 0x00cb }
        throw r2;	 Catch:{ IOException -> 0x009a, all -> 0x00cb }
    L_0x00cb:
        r0 = move-exception;
        r3 = r1;
        o.dnw.ˎ(r1);
        o.dnw.ˎ(r3);
        throw r0;
        throw r0;	 Catch:{ IOException -> 0x009a, all -> 0x00cb }
        r4 = r0;
        r0 = r3;
        r3 = 0;
        r3 = r6.openFileOutput(r5, r3);	 Catch:{ IOException -> 0x0171, all -> 0x015e }
        r3.write(r0);	 Catch:{ IOException -> 0x0176, all -> 0x0162 }
        o.dnw.ˎ(r3);
        o.dnw.ˎ(r4);
        r0 = ˊ;	 Catch:{ Exception -> 0x0148 }
        r0 = r0 + 81;	 Catch:{ Exception -> 0x0148 }
        r1 = r0 % 128;	 Catch:{ Exception -> 0x0148 }
        ʽ = r1;	 Catch:{ Exception -> 0x0148 }
        r0 = r0 % 2;	 Catch:{ Exception -> 0x0148 }
        if (r0 != 0) goto L_0x0142;
        r0 = 66;
        switch(r0) {
            case 66: goto L_0x00f6;
            default: goto L_0x00f6;
        };
        r0 = r2;
        goto L_0x0099;
        r3 = 42;
        switch(r3) {
            case 13: goto L_0x0081;
            default: goto L_0x00fe;
        };
        r10 = r4;
        r4 = r0;
        r0 = r10;
        goto L_0x00d7;
        r0 = r6.getAssets();	 Catch:{ IOException -> 0x009a, all -> 0x00cb }
        r3 = 2;
        r3 = new java.lang.Object[r3];	 Catch:{ all -> 0x014a }
        r4 = 1;	 Catch:{ all -> 0x014a }
        r3[r4] = r5;	 Catch:{ all -> 0x014a }
        r4 = 0;	 Catch:{ all -> 0x014a }
        r3[r4] = r0;	 Catch:{ all -> 0x014a }
        r0 = 5;	 Catch:{ all -> 0x014a }
        r4 = 0;	 Catch:{ all -> 0x014a }
        r7 = 15235; // 0x3b83 float:2.1349E-41 double:7.527E-320;	 Catch:{ all -> 0x014a }
        r0 = o.avb.ˏ(r0, r4, r7);	 Catch:{ all -> 0x014a }
        r0 = (java.lang.Class) r0;	 Catch:{ all -> 0x014a }
        r4 = "ˏ";	 Catch:{ all -> 0x014a }
        r7 = 2;	 Catch:{ all -> 0x014a }
        r7 = new java.lang.Class[r7];	 Catch:{ all -> 0x014a }
        r8 = 0;	 Catch:{ all -> 0x014a }
        r9 = android.content.res.AssetManager.class;	 Catch:{ all -> 0x014a }
        r7[r8] = r9;	 Catch:{ all -> 0x014a }
        r8 = 1;	 Catch:{ all -> 0x014a }
        r9 = java.lang.String.class;	 Catch:{ all -> 0x014a }
        r7[r8] = r9;	 Catch:{ all -> 0x014a }
        r0 = r0.getMethod(r4, r7);	 Catch:{ all -> 0x014a }
        r4 = 0;	 Catch:{ all -> 0x014a }
        r0 = r0.invoke(r4, r3);	 Catch:{ all -> 0x014a }
        r0 = (java.io.InputStream) r0;	 Catch:{ all -> 0x014a }
        r3 = r0.available();	 Catch:{ IOException -> 0x016b, all -> 0x0159 }
        r4 = new byte[r3];	 Catch:{ IOException -> 0x016b, all -> 0x0159 }
        r7 = r0.read(r4);	 Catch:{ IOException -> 0x016b, all -> 0x0159 }
        if (r7 == r3) goto L_0x00f9;
        r3 = 13;
        goto L_0x00fb;
        r0 = 12;
        goto L_0x00f3;
        r0 = r3;
        goto L_0x003f;
    L_0x0148:
        r0 = move-exception;
        throw r0;
    L_0x014a:
        r0 = move-exception;
        r2 = r0.getCause();	 Catch:{ IOException -> 0x009a, all -> 0x00cb }
        if (r2 == 0) goto L_0x0152;	 Catch:{ IOException -> 0x009a, all -> 0x00cb }
        throw r2;	 Catch:{ IOException -> 0x009a, all -> 0x00cb }
        throw r0;	 Catch:{ IOException -> 0x009a, all -> 0x00cb }
    L_0x0153:
        r0 = move-exception;
        throw r0;
        r0 = r1;
        goto L_0x0099;
    L_0x0159:
        r2 = move-exception;
        r3 = r0;
        r0 = r2;
        goto L_0x00cd;
    L_0x015e:
        r0 = move-exception;
        r3 = r4;
        goto L_0x00cd;
    L_0x0162:
        r0 = move-exception;
        r1 = r3;
        r3 = r4;
        goto L_0x00cd;
    L_0x0167:
        r0 = move-exception;
        r1 = r2;
        goto L_0x00cd;
    L_0x016b:
        r2 = move-exception;
        r3 = r0;
        r0 = r2;
        r2 = r1;
        goto L_0x009d;
    L_0x0171:
        r0 = move-exception;
        r2 = r1;
        r3 = r4;
        goto L_0x009d;
    L_0x0176:
        r0 = move-exception;
        r2 = r3;
        r3 = r4;
        goto L_0x009d;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.appgallery.downloadengine.impl.smartmerge.jni.AppPatch.ˋ():java.lang.String");
    }

    private static java.lang.String ˏ(int r9, short r10, int r11) {
        /* JADX: method processing error */
/*
Error: jadx.core.utils.exceptions.JadxOverflowException: Regions stack size limit reached
	at jadx.core.utils.ErrorsCounter.addError(ErrorsCounter.java:37)
	at jadx.core.utils.ErrorsCounter.methodError(ErrorsCounter.java:61)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:33)
	at jadx.core.dex.visitors.DepthTraversal.visit(DepthTraversal.java:17)
	at jadx.core.ProcessClass.process(ProcessClass.java:37)
	at jadx.api.JadxDecompiler.processClass(JadxDecompiler.java:306)
	at jadx.api.JavaClass.decompile(JavaClass.java:62)
*/
        /*
        r5 = 0;
        r0 = r11 * 4;
        r1 = r0 + 16;
        r7 = ˋ;
        r0 = r10 * 4;
        r3 = 109 - r0;
        r0 = r9 * 2;
        r0 = r0 + 4;
        r2 = new byte[r1];
        r1 = r1 + -1;
        if (r7 != 0) goto L_0x0030;
    L_0x0015:
        r3 = r2;
        r4 = r5;
        r6 = r0;
        r2 = r0;
        r0 = r1;
    L_0x001a:
        r0 = -r0;
        r0 = r0 + r2;
        r2 = r0 + -17;
        r6 = r6 + 1;
    L_0x0020:
        r0 = (byte) r2;
        r3[r4] = r0;
        if (r4 != r1) goto L_0x002b;
    L_0x0025:
        r0 = new java.lang.String;
        r0.<init>(r3, r5);
        return r0;
    L_0x002b:
        r0 = r7[r6];
        r4 = r4 + 1;
        goto L_0x001a;
    L_0x0030:
        r4 = r5;
        r6 = r0;
        r8 = r3;
        r3 = r2;
        r2 = r8;
        goto L_0x0020;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.appgallery.downloadengine.impl.smartmerge.jni.AppPatch.ˏ(int, short, int):java.lang.String");
    }

    public static AppPatch ˏ() {
        AppPatch appPatch;
        synchronized (ॱ) {
            if (ˏ == null) {
                ˏ = new AppPatch();
                ˏ.ˊ();
            }
            appPatch = ˏ;
        }
        return appPatch;
    }

    private void ˊ() {
        try {
            System.loadLibrary("apppatch");
        } catch (UnsatisfiedLinkError e) {
            bnc.ˎ.ˏ("AppPatch", "loadLibrary error, trying to load lib from local agagin " + e.toString());
            ˎ();
        }
    }

    private void ˎ() {
        try {
            String ˋ = ˋ();
            if (ˋ != null) {
                System.load(ˋ);
            }
        } catch (Throwable e) {
            bnc.ˎ.ˊ("AppPatch", "loadlibFromlocal error:", e);
        }
    }

    public synchronized int ˊ(String str, String str2, String str3) {
        File file = new File(str2);
        if (!file.exists()) {
            try {
                if (!file.createNewFile()) {
                    bnc.ˎ.ˋ("AppPatch", "createNewFile failed!");
                }
            } catch (IOException e) {
                byte b = (byte) ˋ[16];
                byte b2 = (byte) b;
                bnc.ˎ.ˏ("AppPatch", ˏ(b, b2, (byte) b2) + e.toString());
            }
        }
        return patch(str, str2, str3);
    }
}
